﻿using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using O1.Kernel.Storage.Transactions;

namespace Tests.O1.Behaviors
{
    [TestClass]
    public class TxBehaviors
    {
        [TestMethod, TestCategory("Unit Test")]
        public void TxStatusPendingIsGreaterThanCommitted()
        {
            long txId = 10220;
            var pending = txId.AsPending();
            var committed = txId.AsCommitted();
            pending.Should().Be(txId);
            committed.Should().BeLessThan(txId);
        }

        [TestMethod, TestCategory("Unit Test")]
        public void TxStatusWithId0PendingIsGreaterThanCommitted()
        {
            long txId = 0;
            var pending = txId.AsPending();
            var committed = txId.AsCommitted();
            pending.Should().Be(txId);
            committed.Should().BeLessThan(txId);
        }

        ////[TestMethod, TestCategory("Unit Test")]
        ////public void MultiVersionScavengeStrategyHandlesCompetingThreads()
        ////{
        ////    var target = new MultiVersionBinaryStorage();
        ////    var taskEvens = new Task(() => { for (ulong i = 0; i < 1000; i += 2) { target.SetLastCommittedTx(i); } });
        ////    var taskOdds = new Task(() => { for (ulong i = 1; i < 1000; i += 2) { target.SetLastCommittedTx(i); } });

        ////    taskEvens.Start();
        ////    taskOdds.Start();

        ////    Task.WaitAll(taskOdds, taskEvens);
        ////    target.LastCommittedTxId.Should().Be(((ulong)999).SetCommitted());
        ////}
    }
}
